package com.backend.service.impl;

import com.backend.common.PageRequest;
import com.backend.common.PageResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.backend.entity.RoomCategory;
import com.backend.service.RoomCategoryService;
import com.backend.mapper.RoomCategoryMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 *
 */
@Service
public class RoomCategoryServiceImpl extends ServiceImpl<RoomCategoryMapper, RoomCategory>
    implements RoomCategoryService{


    @Override
    public PageResponse page(PageRequest pageRequest) {
        Page<RoomCategory> page = new Page<>(pageRequest.getCurrentPage(), pageRequest.getPageSize());
        HashMap<String, Object> params = pageRequest.getParams();
        QueryWrapper<RoomCategory> queryWrapper = new QueryWrapper<>();

        if (params.size() > 0) {
            for (String key: params.keySet()) {
                System.out.println("这是：" + key);
                if (StringUtils.isNotBlank(params.get(key).toString()))
                    queryWrapper.eq( key, params.get(key));
            }
        }
        this.page(page, queryWrapper);
        return new PageResponse(page);
    }
}




